#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;

int main(int argc, char** argv){
    cv::Mat src1, src2, diff12;
    if (argc < 3) {
        cout << "parameters miss!\n"
            << argv[0] << " 1.jpg 2.jpg" << endl;
        return -1;
    }

    src1 = cv::imread(argv[1]);
    src2 = cv::imread(argv[2]);

    cv::absdiff(src1, src2, diff12);
    cv::imshow("absdiff", diff12);

    cv::Mat cleandiff, dirtydiff, kernel;
    cv::erode(diff12, cleandiff, kernel);
    cv::dilate(cleandiff, cleandiff, kernel);
    cv::imshow("clean_diff", cleandiff);

    cv::dilate(diff12, dirtydiff, kernel);
    cv::erode(dirtydiff, dirtydiff, kernel);
    cv::imshow("dirty_diff", dirtydiff);

    cv::waitKey(0);
    return 0;
}